import mc

def get_username_password():
    """
    Get username and password from configuration or prompt dialog 
    if they dont exist.
    """
    config = mc.GetApp().GetLocalConfig()
    username = config.GetValue("username")
    password = config.GetValue("password")
    
    # Check username
    if not username:
        username = mc.ShowDialogKeyboard("Username", "", False)
        config.SetValue("username", username)
    
    # Check password
    if not password:
        password = mc.ShowDialogKeyboard("Password", "", True)
        config.SetValue("password", password)
    return (username, password)

def reset_username_password():
    """Reset credidentals if user selected Cancel"""
    if mc.ShowDialogConfirm("Reset your username and password?", 
                            'You have to quit and re-enter this application.', 'Cancel', 'OK'):
        config = mc.GetApp().GetLocalConfig()
        config.SetValue("username", '')
        config.SetValue("password", '')
